package com.socket.socketMoreTest;

import com.socket.socketObjTest.Pet;

import java.io.*;
import java.net.Socket;

/**
 * PetClient--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-14 11:07
 **/
public class PetClient {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("localhost", 9091);

        OutputStream os = socket.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(os);

        Pet pet = new Pet("pig1", "blue1");
        oos.writeObject(pet);

        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String repay;
        while ((repay = br.readLine()) != null) {
            System.out.println("我是宠物主人，宠物店响应为：" + repay);
        }
        br.close();
        is.close();
        oos.close();
        os.close();
        socket.close();
    }

}
